package com.vframework.rest;

import java.util.logging.Filter;
import java.util.logging.LogRecord;

import javax.ws.rs.ApplicationPath;

import org.apache.log4j.Logger;
import org.glassfish.jersey.filter.LoggingFilter;
import org.glassfish.jersey.jackson.JacksonFeature;
import org.glassfish.jersey.media.multipart.MultiPartFeature;
import org.glassfish.jersey.server.ResourceConfig;

import com.vframework.rest.filter.CORSFilter;
import com.vframework.rest.filter.JerseyAuthenticationFilter;
import com.vframework.rest.filter.ObjectMapperProvider;

/***************************************************************
 * Name:        CustomApplication.java
 * Create At:   2018年4月11日
 * Module:      
 * Description: [功能描述]
 * @author      shanzhitong
 * ------------------------------------------------------------
 * 修改历史
 * 序号         日期                       修改人               修改原因
 * 1    2018年4月11日      shanzhitong    
 * 2
***************************************************************/
@ApplicationPath("rest")
public class CustomApplication extends ResourceConfig {
	private static final Logger LOGGER = Logger.getLogger(CustomApplication.class.getName());
	public CustomApplication(){
		packages("com.vframework.rest.resources", "com.admin.rest.resources");
		register(JerseyAuthenticationFilter.class);
		register(CORSFilter.class);
		register(LoggingFilter.class);
		
		java.util.logging.Logger javaLogger = java.util.logging.Logger.getLogger(LoggingFilter.class.getName());
        javaLogger.setFilter(new Filter() {
			@Override
			public boolean isLoggable(LogRecord record) {
				LOGGER.info(record.getMessage());
				return false;
			}
		});
		register(new LoggingFilter(javaLogger, true));
		register(MultiPartFeature.class);  
		
		register(ObjectMapperProvider.class);
        register(JacksonFeature.class);
	}
}
